﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Business;

namespace University.Workshop.WinApp
{
    public partial class ConsultationRegister : Form
    {
        string FamilyHistory = String.Empty;
        string PastMedicalHistory = String.Empty;
        string PersonalHistory = String.Empty;
        string GeneralSymptoms = String.Empty;

        public string PatientId;
        public string DoctorId;
        public string AppointmentId;

        public ConsultationRegister()
        {
            InitializeComponent();
            cbxCurrentCondition.SelectedIndex = 0;
        }

        private void tabPersonalHistory_Click(object sender, EventArgs e)
        {

        }

        private void tabSignosPaciente_Click(object sender, EventArgs e)
        {

        }

        private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnGuardar_Click(object sender, EventArgs e)
        {
            //ConsultationManager cm = new ConsultationManager();
            try
            {
                VerifyFamilyHistoryCheckBoxes();

                VerifyPastMedicalHistoryCheckBoxes();

                VerifyPersonalHistoryCheckBoxes();

                VerifyGeneralSymptomsCheckBoxes();

                ConsultationManager.RegisterNewConsultation(

                //cm.RegisterNewConsultation(
                    txtPatientId.Text,
                    txtDoctorId.Text,
                    int.Parse(txtAppointmentId.Text),


                    FamilyHistory,
                    txtFamilyHistoryDetails.Text,
                    PastMedicalHistory,
                    txtPastMedicalHistoryDetails.Text,
                    PersonalHistory,
                    txtPersonalHistoryDetails.Text,

                    txtHeartRate.Text,
                    txtBloodPressure.Text,
                    txtRespirationRate.Text,
                    txtTemperature.Text,
                    txtCurrentWeight.Text,
                    txtHeight.Text,
                    txtIdealWeight.Text,

                    txtChiefComplaints.Text,
                    GeneralSymptoms,

                    cbxCurrentCondition.Text,
                    txtCurrentConditionDetails.Text,
                    txtPreviousDiagnoses.Text,
                    txtPreviouslyEmployedTherapeutic.Text,

                    txtDigestiveApparatus.Text,
                    txtCardiovascularApparatus.Text,
                    txtRespiratoryApparatus.Text,
                    txtUrinaryApparatus.Text,
                    txtGenitalApparatus.Text,
                    txtHematologicApparatus.Text,
                    txtEndocrineSystem.Text,
                    txtOsteomuscularSystem.Text,
                    txtNervousSystem.Text,
                    txtSensorialSystem.Text,
                    txtPsicosomatic.Text,

                    txtGeneralExamination.Text,
                    txtExaminationHead.Text,
                    txtExaminationNeck.Text,
                    txtExaminationChest.Text,
                    txtExaminationAbdomen.Text,
                    txtExaminationMembers.Text,
                    txtExaminationGenitals.Text,

                    
                    txtComments.Text,
                    txtDiagnosis.Text,
                    txtPrognosis.Text,
                    txtTreatment.Text
                );
                MessageBox.Show("Consulta registrada exitosamente");
                this.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex);
                
            }
        }

        private void VerifyGeneralSymptomsCheckBoxes()
        {
            if (chkAsthenia.Checked)
                GeneralSymptoms += "1-";
            if (chkAdynamia.Checked)
                GeneralSymptoms += "2-";
            if (chkAnorexia.Checked)
                GeneralSymptoms += "3-";
            if (chkFever.Checked)
                GeneralSymptoms += "4-";
            if (chkWeightLoss.Checked)
                GeneralSymptoms += "5";
        }

        private void VerifyPersonalHistoryCheckBoxes()
        {
            if (chkSmoking.Checked)
                PersonalHistory += "1-" + txtSmoking.Text + "-";
            if (chkAlcoholism.Checked)
                PersonalHistory += "2-" + txtAlcoholism.Text + "-";
            if (chkAddiction.Checked)
                PersonalHistory += "3-" + txtAddiction.Text + "-";
            if (chkPhysicalActivity.Checked)
                PersonalHistory += "4-" + txtPhysicalActivity.Text + "-";
            if (chkImmunizations.Checked)
                PersonalHistory += "5-";
            if (chkAllergies.Checked)
                PersonalHistory += "6-";
        }

        private void VerifyPastMedicalHistoryCheckBoxes()
        {
            if (chkChildhoodInfectious.Checked)
                PastMedicalHistory += "1-";
            if (chkTBPato.Checked)
                PastMedicalHistory += "2-";
            if (chkVenerealDiseases.Checked)
                PastMedicalHistory += "3-";
            if (chkTyphoidFever.Checked)
                PastMedicalHistory += "4-";
            if (chkSalmonellosis.Checked)
                PastMedicalHistory += "5-";
            if (chkPneumonia.Checked)
                PastMedicalHistory += "6-";
            if (chkMalaria.Checked)
                PastMedicalHistory += "7-";
            if (chkParasites.Checked)
                PastMedicalHistory += "8-";
            if (chkAllergicDiseases.Checked)
                PastMedicalHistory += "9-";
            if (chkArticularConditions.Checked)
                PastMedicalHistory += "10-";
            if (chkSurgeries.Checked)
                PastMedicalHistory += "11-";
            if (chkHospitalizations.Checked)
                PastMedicalHistory += "12-";
            if (chkInjuries.Checked)
                PastMedicalHistory += "13-";
            if (chkLossConsciousness.Checked)
                PastMedicalHistory += "14-";
            if (chkDrugIntolerance.Checked)
                PastMedicalHistory += "15-";
            if (chkTransfusions.Checked)
                PastMedicalHistory += "16";
        }

        private void VerifyFamilyHistoryCheckBoxes()
        {
            if (chkTB.Checked)
                FamilyHistory += "1-";
            if (chkDiabetes.Checked)
                FamilyHistory += "2-";
            if (chkMellitus.Checked)
                FamilyHistory += "3-";
            if (chkHypertension.Checked)
                FamilyHistory += "4-";
            if (chkCarcinomas.Checked)
                FamilyHistory += "5-";
            if (chkHeart.Checked)
                FamilyHistory += "6-";
            if (chkLiver.Checked)
                FamilyHistory += "7-";
            if (chkKidney.Checked)
                FamilyHistory += "8-";
            if (chkEndocrine.Checked)
                FamilyHistory += "9-";
            if (chkMentalIllness.Checked)
                FamilyHistory += "10-";
            if (chkEpilepsy.Checked)
                FamilyHistory += "11-";
            if (chkAsthma.Checked)
                FamilyHistory += "12-";
            if (chkHematologicDiseases.Checked)
                FamilyHistory += "13";
        }

        private void btnRegistrarReceta_Click(object sender, EventArgs e)
        {
            AddPrescriptionView AddPrescriptionView;
            AddPrescriptionView = new AddPrescriptionView();
            AddPrescriptionView.Visible = true;
        }

        private void chkSmoking_CheckedChanged(object sender, EventArgs e)
        {
            if (chkSmoking.Checked)
                txtSmoking.Enabled = true;
            else
                txtSmoking.Enabled = false;
        }

        private void chkAlcoholism_CheckedChanged(object sender, EventArgs e)
        {
            if (chkAlcoholism.Checked)
                txtAlcoholism.Enabled = true;
            else
                txtAlcoholism.Enabled = false;
        }

        private void chkAddiction_CheckedChanged(object sender, EventArgs e)
        {
            if (chkAddiction.Checked)
                txtAddiction.Enabled = true;
            else
                txtAddiction.Enabled = false;
        }

        private void chkPhysicalActivity_CheckedChanged(object sender, EventArgs e)
        {
            if (chkPhysicalActivity.Checked)
                txtPhysicalActivity.Enabled = true;
            else
                txtPhysicalActivity.Enabled = false;
        }

        private void btnBuscarReserva_Click(object sender, EventArgs e)
        {
            SearchAppointment searchAppointmentForm;
            searchAppointmentForm = new SearchAppointment(this);
            //searchAppointmentForm.Visible = true;
            searchAppointmentForm.ShowDialog();

            txtPatientId.Text = PatientId;
            txtDoctorId.Text = DoctorId;
            txtAppointmentId.Text = AppointmentId;

            if (string.IsNullOrEmpty(PatientId) ||
                string.IsNullOrEmpty(DoctorId) ||
                string.IsNullOrEmpty(AppointmentId))
            {
            }
            else
            {
                btnGuardar.Enabled = true;
                btnGuardar.Visible = true;

                //btnRegistrarInsumos.Enabled = true;
                //btnRegistrarInsumos.Visible = true;

                btnRegistrarReceta.Enabled = true;
                btnRegistrarReceta.Visible = true;

                btnVerInsumos.Visible = true;

                btnVerInsumos.Enabled = true;
                btnVerInsumos.Visible = true;

                tabDatosPaciente.Enabled = true;
                tabDatosConsulta.Enabled = true;
                
            }
            

        }

        private void btnVerInsumos_Click(object sender, EventArgs e)
        {
            GetAllMedicalSupplies getall = new GetAllMedicalSupplies();
            this.Visible = false;
            if (getall.ShowDialog() == DialogResult.Cancel)
                this.Visible = true;
        }

        private void btnVerInsumos_Click_1(object sender, EventArgs e)
        {
            GetAllMedicalSupplies getall = new GetAllMedicalSupplies();
            this.Visible = false;
            if (getall.ShowDialog() == DialogResult.Cancel)
                this.Visible = true;
        }

       
    }
}
